package j03sisuo;

public class J2 {
    static Object lock = new Object();
    public static void main(String[] args) throws InterruptedException {

        Thread t1 = new Thread(()->{
            System.out.println("enter t1");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            //上锁
            synchronized (lock){
                System.out.println("t1 enter lock");
            }
            System.out.println("t1 end");
            //唤醒wait的lock
            try {
                synchronized (lock){
                    //唤醒wait的lock
                    lock.notify();
                }
            }catch (Exception e){
                System.out.println("e = " + e);
            }
        });

        t1.start();

        synchronized (lock){
            //1，开锁
            //2，程序暂停
            lock.wait();
            System.out.println("这里不会走");
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
        System.out.println("lock 解开");



    }
}
